package top.tagao.yygh.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.tagao.yygh.cmn.client.DictFeignClient;
import top.tagao.yygh.enums.DictEnum;
import top.tagao.yygh.model.user.Patient;
import top.tagao.yygh.user.mapper.PatientMapper;
import top.tagao.yygh.user.service.PatientService;

import java.sql.Wrapper;
import java.util.List;

/**
 * @author fu-xiao-liu
 * @Date 2022/3/12 17:10
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {

    @Autowired
    DictFeignClient dictFeignClient;

    /**
     * @date  就诊人列表
     * @param userID
     * @return java.util.List<top.tagao.yygh.model.user.Patient>
     */
    @Override
    public List<Patient> findAllUserId(Long userID) {

        QueryWrapper<Patient> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userID);

        List<Patient> patientList = baseMapper.selectList(wrapper);
        patientList.stream().forEach(item ->{
            this.pagePatient(item);
        });
        return patientList;
    }

    /**
     * @date  就诊人查看详情
     * @param id
     * @return top.tagao.yygh.model.user.Patient
     */
    @Override
    public Patient getPatientById(Long id) {
        Patient patient = baseMapper.selectById(id);
        this.pagePatient(patient);
        return patient;
    }

    /**
     * @date   通过远程调用，得到编码对应具体内容，查询数据字典表内容,进行数据封装
     */
    private void pagePatient(Patient patient) {
        //就诊人证件类型
        String certificatesType = dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), patient.getCertificatesType());
        //联系人证件类型
        String contactsCertificatesType = dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), patient.getContactsCertificatesType());
        //省
        String province = dictFeignClient.getName(patient.getProvinceCode());
        //市
        String city= dictFeignClient.getName(patient.getCityCode());
        //区
        String district = dictFeignClient.getName(patient.getDistrictCode());

        patient.getParam().put("certificatesTypeString", certificatesType);
        patient.getParam().put("contactsCertificatesTypeString", contactsCertificatesType);
        patient.getParam().put("provinceString", province);
        patient.getParam().put("cityString", city);
        patient.getParam().put("districtString", district);
        patient.getParam().put("fullAddress", province + city + district + patient.getAddress());
    }
}
